/* Admin.java
 * 
 * Alfred Olschnoegger
 * 24.05.2008
 */

package presentation.controller;

import exceptions.GameNotExistingException;
import exceptions.LogWriter;
import presentation.controller.Redirect;
import application.GameInfoProvider;
import application.GameStarter;
import application.ServerInfoProvider;

/**
 * The class Admin is managing the administrative actions.
 *
 * @date 24.05.2008
 * @author Alfred Olschnoegger
 */
public class Admin extends HttpBaseController {

	/**
	 * processes the administrative tasks
	 */
	public void process() {
		if(m_Arguments.get("task").equalsIgnoreCase("newGame")) {
			new GameStarter().startGame(
					m_Arguments.get("name"),
					Double.parseDouble(m_Arguments.get("xlat")),
					Double.parseDouble(m_Arguments.get("xlong")),
					Double.parseDouble(m_Arguments.get("ylat")),
					Double.parseDouble(m_Arguments.get("ylong")),
					Integer.parseInt(m_Arguments.get("duration")));
		} else if(m_Arguments.get("task").equalsIgnoreCase("stop")) {
			try {
				new GameInfoProvider(Integer.parseInt(m_Arguments.get("game"))).stop();
			} catch (Exception e) {
				new LogWriter().write(e);
				e.printStackTrace();
			} 
		}
		

		m_Request.setAttribute("games", new ServerInfoProvider().getGameValues());
		redirect("admin.jsp");
		
		

	}
}


// end of Admin.java
